package com.cms.recursoshumanos.activity.pantallas_principal;

import com.example.frontendrecursoshumanos.R;

import com.cms.recursoshumanos.activity.beneficios_lot.ListaBeneficiosAdmActivity;
import com.cms.recursoshumanos.activity.catalogo.ListaTipoArticuloActivity;
import com.cms.recursoshumanos.activity.catalogo.carrito.CarritoCompraActivity;
import com.cms.recursoshumanos.activity.directorio.DirectorioMainActivity;
import com.cms.recursoshumanos.activity.eventos.ListaTipoEventoActivity;
import com.cms.recursoshumanos.activity.menu_comida.ListaTipoMenuActivity;
import com.cms.recursoshumanos.activity.ocio.ListaOcioActivity;
import com.cms.recursoshumanos.activity.ocio.reservacion.ListaReservacionActivity;
import com.cms.recursoshumanos.activity.ocio.reservacion.SetReservacionActivity;
import com.cms.recursoshumanos.activity.user.UserInfoActicity;
import com.cms.recursoshumanos.activity.vacaciones.DetailVacacionesActivity;
import com.cms.recursoshumanos.constant.Constant;
import com.cms.recursoshumanos.handler.BeneficiosAdministrativosActivityHandler;
import com.cms.recursoshumanos.handler.InfoUserActivityHandler;
import com.cms.recursoshumanos.handler.ListaOcioActivityHandler;
import com.cms.recursoshumanos.handler.ListaReservacionActivityHandler;
import com.cms.recursoshumanos.handler.ListaTipoArticuloActivityHandler;
import com.cms.recursoshumanos.handler.ListaTipoEventosActivityHandler;
import com.cms.recursoshumanos.handler.ListaTipoMenuActivityHandler;
import com.cms.recursoshumanos.object.Usuario;
import com.cms.recursoshumanos.utilities.Tool;

import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.view.Menu;
import android.view.View;

public class prueba_cambio extends Activity {

	protected static InfoUserAsync infoUserAsyncTask;
	protected static TipoEventoAsync tipoEventoAsyncTask;
	protected static MenuComedorAsync menuComedorAsyncTask;
	protected static TipoArticuloAsync tipoArticuloAsyncTask;
	protected static ListaOcioAsync ocioAsyncTask;
	protected static ListaReservacionAsync reservacionAsyncTask;
	protected static SetReservacionAsync setReservacionAsyncTask;
	protected static BeneficioAdmAsync listaBeneficioAsyncTask;
	
	private ProgressDialog dialog;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_men1_principal);

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) 
	{
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.menu, menu);
		return true;
	}
	public void showDirectorio(View v)
    {
		goDirectorio();
	}
	public void showCarrito(View v)
    {
		goCarrito();
	}
	public void showVacaciones(View v)
    {
		goVacaciones();
	}
	public void showInfoPersona(View v)
    {
		findInfoUser();
	}
	
	public void showMenuComedor(View v)
    {
		findInfoTipoMenu();
	}
	public void showListaOcio(View v)
    {
		findListaOcio();
	}
	public void showTipoArticulo(View v)
    {
		findInfoTipoArticulo();
	}
	public void showTipoEvento(View v)
    {
		findInfoTipoEvento();
	}
	
	public void showListaReservacion(View v)
    {
		findListaReservacion();
	}
	
	public void showSetReservacion(View v)
    {
		findSetReservacion();
	}
	
	public void showBeneficios(View v)
    {
		findBeneficioAdministrativo();
	}
	
	
	protected void findBeneficioAdministrativo()
	{
		listaBeneficioAsyncTask = new BeneficioAdmAsync();
		listaBeneficioAsyncTask.execute();
	}
	protected void findSetReservacion()
	{
		setReservacionAsyncTask = new SetReservacionAsync();
		setReservacionAsyncTask.execute();
	}
	protected void findInfoUser()
	{
		infoUserAsyncTask = new InfoUserAsync();
		infoUserAsyncTask.execute();
	}
	
	protected void findInfoTipoEvento()
	{
		tipoEventoAsyncTask = new TipoEventoAsync();
		tipoEventoAsyncTask.execute();
	}
	protected void findInfoTipoMenu()
	{
		menuComedorAsyncTask = new MenuComedorAsync();
		menuComedorAsyncTask.execute();
	}
	protected void findInfoTipoArticulo()
	{
		tipoArticuloAsyncTask = new TipoArticuloAsync();
		tipoArticuloAsyncTask.execute();
	}
	protected void findListaOcio()
	{
		ocioAsyncTask = new ListaOcioAsync();
		ocioAsyncTask.execute();
	}
	protected void findListaReservacion()
	{
		reservacionAsyncTask = new ListaReservacionAsync();
		reservacionAsyncTask.execute();
	}
	public void goInfoUser()
	{
		Intent intent = new Intent(prueba_cambio.this, UserInfoActicity.class);
		startActivity(intent);
	}
	public void goTipoMenu()
	{
		Intent intent = new Intent(prueba_cambio.this, ListaTipoMenuActivity.class);
		startActivity(intent);
	}
	public void goTipoEvento()
	{
		Intent intent = new Intent(prueba_cambio.this, ListaTipoEventoActivity.class);
		startActivity(intent);
	}
	public void goTipoArticulo()
	{
		Intent intent = new Intent(prueba_cambio.this, ListaTipoArticuloActivity.class);
		startActivity(intent);
	}
	public void goListaOcio()
	{
		Intent intent = new Intent(prueba_cambio.this, ListaOcioActivity.class);
		startActivity(intent);
	}
	public void goListaReservacion()
	{
		Intent intent = new Intent(prueba_cambio.this, ListaReservacionActivity.class);
		startActivity(intent);
	}
	public void goSetReservacion()
	{
		Intent intent = new Intent(prueba_cambio.this, SetReservacionActivity.class);
		startActivity(intent);
	}
	public void goBeneficioAdm()
	{
		Intent intent = new Intent(prueba_cambio.this, ListaBeneficiosAdmActivity.class);
		startActivity(intent);
	}
	public void goVacaciones()
	{
		Intent intent = new Intent(prueba_cambio.this, DetailVacacionesActivity.class);
		startActivity(intent);
	}
	public void goCarrito()
	{
		Intent intent = new Intent(prueba_cambio.this, CarritoCompraActivity.class);
		startActivity(intent);
	}
	public void goDirectorio()
	{
		Intent intent = new Intent(prueba_cambio.this, DirectorioMainActivity.class);
		startActivity(intent);
	}
	private class InfoUserAsync extends AsyncTask<String, Void, String>
	{
		private Usuario elUsuario;
		
		public InfoUserAsync()
		{
			
		}
		@SuppressWarnings("deprecation")
		@Override
		protected void onPreExecute()
		{
			showDialog(0);
			dialog = ProgressDialog.show(prueba_cambio.this, "Espere","Cargando...",true );
		}
	
		@Override
		protected String doInBackground(String... arg0) 
		{
			//HttpResponse nu = ConexionHandler.login(arg0[0], arg0[1]);
			InfoUserActivityHandler handler = new InfoUserActivityHandler();

			String result = handler.GetUserInfo(this.elUsuario.getNombre_Usuario(),	
													this.elUsuario.getPassword());
			return result;
			//return ConexionHandler.makeLogin(LoginActivity.this,arg0[0], arg0[1]);
		}
		
		@Override
		public void onPostExecute(String  result)
		{
			
			dialog.cancel();
			String str_result = result;
			
			if (str_result.equals(Constant.CODE_OK))
			{ 
				goInfoUser();
			}
			else 
			{
				Tool.getInstance().showMessage( str_result);
			}
			this.cancel(true);
			
			
		}
		
	}
	
	private class MenuComedorAsync extends AsyncTask<String, Void, String>
	{
		
		private Usuario elUsuario;
		
		public MenuComedorAsync()
		{
			
		}

		@SuppressWarnings("deprecation")
		@Override
		protected void onPreExecute()
		{
			showDialog(0);
			dialog = ProgressDialog.show(prueba_cambio.this, "Espere","Cargando...",true );
		}
	
		@Override
		protected String doInBackground(String... arg0) 
		{
			ListaTipoMenuActivityHandler handler = new ListaTipoMenuActivityHandler();
			String result = handler.getListadoTipoMenu(this.elUsuario.getNombre_Usuario(), 
														this.elUsuario.getPassword());
			return result;
		}
		
		@Override
		public void onPostExecute(String  result)
		{
			dialog.cancel();
			String str_result = result;
			
			if (str_result.equals(Constant.CODE_OK))
			{ 
				goTipoMenu();
			}
			else 
			{
				Tool.getInstance().showMessage( str_result);
			}
			this.cancel(true);
			
		}
		
	}
	
	private class TipoEventoAsync extends AsyncTask<String, Void, String>
	{
		
		private Usuario elUsuario;
		
		public TipoEventoAsync()
		{
			
		}
		@SuppressWarnings("deprecation")
		@Override
		protected void onPreExecute()
		{
			showDialog(0);
			dialog = ProgressDialog.show(prueba_cambio.this, "Espere","Cargando...",true );
		}
	
		@Override
		protected String doInBackground(String... arg0) 
		{
			ListaTipoEventosActivityHandler handler = new ListaTipoEventosActivityHandler();
			String result = handler.getListaTipoEvento(this.elUsuario.getNombre_Usuario(),
														this.elUsuario.getPassword());
			return result;
		}
		
		@Override
		public void onPostExecute(String  result)
		{
			dialog.cancel();
			String str_result = result;
			
			if (str_result.equals(Constant.CODE_OK))
			{ 
				goTipoEvento();
			}
			else 
			{
				Tool.getInstance().showMessage( str_result);
			}
			this.cancel(true);
			
		}
		
	}
	private class TipoArticuloAsync extends AsyncTask<String, Void, String>
	{

		private Usuario elUsuario;
		
		public TipoArticuloAsync()
		{
			
		}
		@SuppressWarnings("deprecation")
		@Override
		protected void onPreExecute()
		{
			showDialog(0);
			dialog = ProgressDialog.show(prueba_cambio.this, "Espere","Cargando...",true );
		}
	
		@Override
		protected String doInBackground(String... arg0) 
		{
			ListaTipoArticuloActivityHandler handler = new ListaTipoArticuloActivityHandler();
			String result = handler.getListadoTipoArticulo(this.elUsuario.getNombre_Usuario(),
															this.elUsuario.getPassword());
			return result;
		}
		
		@Override
		public void onPostExecute(String  result)
		{
			dialog.cancel();
			String str_result = result;
			
			if (str_result.equals(Constant.CODE_OK))
			{ 
				goTipoArticulo();
			}
			else 
			{
				Tool.getInstance().showMessage( str_result);
			}
			this.cancel(true);
			
		}
		
	}
	
	private class ListaOcioAsync extends AsyncTask<String, Void, String>
	{

		private Usuario elUsuario;
		
		public ListaOcioAsync()
		{
			
		}
		@SuppressWarnings("deprecation")
		@Override
		protected void onPreExecute()
		{
			showDialog(0);
			dialog = ProgressDialog.show(prueba_cambio.this, "Espere","Cargando...",true );
		}
	
		@Override
		protected String doInBackground(String... arg0) 
		{
			ListaOcioActivityHandler handler = new ListaOcioActivityHandler();
			String result = handler.getListadoOcio(this.elUsuario.getNombre_Usuario(), 
													this.elUsuario.getPassword());
			return result;
		}
		
		@Override
		public void onPostExecute(String  result)
		{
			dialog.cancel();
			String str_result = result;
			
			if (str_result.equals(Constant.CODE_OK))
			{ 
				goListaOcio();
			}
			else 
			{
				Tool.getInstance().showMessage( str_result);
			}
			this.cancel(true);
			
		}
		
	}
	private class ListaReservacionAsync extends AsyncTask<String, Void, String>
	{
		private Usuario elUsuario;
		
		public ListaReservacionAsync()
		{
			
		}
		@SuppressWarnings("deprecation")
		@Override
		protected void onPreExecute()
		{
			showDialog(0);
			dialog = ProgressDialog.show(prueba_cambio.this, "Espere","Cargando...",true );
		}
	
		@Override
		protected String doInBackground(String... arg0) 
		{
			ListaReservacionActivityHandler handler = new ListaReservacionActivityHandler();
			String result = handler.getListadoReservaciones(this.elUsuario.getNombre_Usuario(), 
																this.elUsuario.getPassword(),null);
			return result;
		}
		
		@Override
		public void onPostExecute(String  result)
		{
			dialog.cancel();
			String str_result = result;
			
			if (str_result.equals(Constant.CODE_OK))
			{ 
				goListaReservacion();
			}
			else 
			{
				Tool.getInstance().showMessage( str_result);
			}
			this.cancel(true);
			
		}
		
	}
	private class SetReservacionAsync extends AsyncTask<String, Void, String>
	{
		
		private Usuario elUsuario;
		
		public SetReservacionAsync()
		{
			
		}
		@SuppressWarnings("deprecation")
		@Override
		protected void onPreExecute()
		{
			showDialog(0);
			dialog = ProgressDialog.show(prueba_cambio.this, "Espere","Cargando...",true );
		}
	
		@Override
		protected String doInBackground(String... arg0) 
		{
			ListaOcioActivityHandler handler = new ListaOcioActivityHandler();
			String result = handler.getListadoOcio(this.elUsuario.getNombre_Usuario(), 
													this.elUsuario.getPassword());
			return result;
		}
		
		@Override
		public void onPostExecute(String  result)
		{
			dialog.cancel();
			String str_result = result;
			
			if (str_result.equals(Constant.CODE_OK))
			{ 
				goSetReservacion();
			}
			else 
			{
				Tool.getInstance().showMessage( str_result);
			}
			this.cancel(true);
			
		}
		
	}
	private class BeneficioAdmAsync extends AsyncTask<String, Void, String>
	{
		
		private Usuario elUsuario;
		
		public BeneficioAdmAsync()
		{
			
		}
		@SuppressWarnings("deprecation")
		@Override
		protected void onPreExecute()
		{
			showDialog(0);
			dialog = ProgressDialog.show(prueba_cambio.this, "Espere","Cargando...",true );
		}
	
		@Override
		protected String doInBackground(String... arg0) 
		{
			BeneficiosAdministrativosActivityHandler handler = new BeneficiosAdministrativosActivityHandler();
			String result = handler.getBeneficiosAdministrativos(this.elUsuario.getNombre_Usuario(),
																	this.elUsuario.getPassword());
			return result;
		}
		
		@Override
		public void onPostExecute(String  result)
		{
			dialog.cancel();
			String str_result = result;
			
			if (str_result.equals(Constant.CODE_OK))
			{ 
				goBeneficioAdm();
			}
			else 
			{
				Tool.getInstance().showMessage( str_result);
			}
			this.cancel(true);
			
		}
		
	}
	

}
